#include "kernel.h"

/*struct int* mutex_init(){
	return (int*) 0;
}*/
void mutex_lock(int* lock){

	asm volatile(
		".set mips2\n"
		"0:\n"
		"ori $8, $0, 1\n"
		"ll $9, 0(%0)\n"
		"bne $0, $9, 0b\n"
		"sc $8, 0(%0)\n"
		"beq $0, $8, 0b\n"
		"NOP\n"
		:
		:"r"(lock)
		:"$8","$9"
		);
}

void mutex_unlock(int* lock){

		asm __volatile__ (
			".set mips2\n"
			"0:\n"
			"sw $0, 0(%0)\n"
			"NOP\n"
			:
			:"r"(lock)
			:"$0"
		);
}


